<?php
declare (strict_types = 1);

namespace app\admin\validate;

use think\Validate;

class AdminUser extends Validate
{
    /**
     * 定义验证规则
     * 格式：'字段名' =>  ['规则1','规则2'...]
     *
     * @var array
     */
    protected $rule = [
        'username' => 'require',
        'password' => 'require',
        'captcha'  => 'require|checkCaptcha'
    ];

    /**
     * 定义错误信息
     * 格式：'字段名.规则名' =>  '错误信息'
     *
     * @var array
     */
    protected $message = [
        'username.require' => '请输入用户名',
        'password.require' => '请输入密码',
        'captcha.require' => '请输入验证码',
    ];

    protected function checkCaptcha($value, $rule)
    {
        return captcha_check($value) ? true : '请输入正确的验证码' ;
    }
}
